<template>
	<div id='system'>
		<div class="content-top">
			<span class="h1">查询分析</span>
			<span class="h2">推广汇总查询</span>
		</div>
		<div class="top-btn clearfix">
			<div class="left-content">
				<span class="tip">推广汇总查询分析表</span>
			</div>
			<div>
				<span class="demonstration" style="margin-left: 15px;">开始日期</span>
				<el-date-picker v-model="starTime" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd">
				</el-date-picker>
				<span class="demonstration">结束日期</span>
				<el-date-picker v-model="endTime" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd">
				</el-date-picker>
				<el-button type="primary" @click="look()" style="margin-left: 10px;">查看</el-button>
				<el-button type="primary" @click="excel()">导出excel</el-button>
			</div>
		</div>
		<el-table :data="tableData" style="width: 100%">
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="POPPara" label="推广参数">
			</el-table-column>
			<el-table-column prop="RegTotal" label="累计注册量">
			</el-table-column>
			<el-table-column prop="BrowseTotal" label="累计浏览量">
			</el-table-column>
			<el-table-column prop="RegCurrent" label="当前注册量">
			</el-table-column>
			<el-table-column prop="BrowseCurrent" label="当前浏览量">
			</el-table-column>
		</el-table>
		<div class="pages">
			<el-pagination small :current-page="index" @current-change="handleCurrentChange" layout="prev, pager, next" :total="total" background prev-text='上一页' next-text='下一页'>
			</el-pagination>
		</div>
	</div>
</template>

<script>
	import api from '../../../api/api'
	export default {
		name: 'popquery',
		data() {
			return {
				starTime: new Date(), //开始日期
				endTime: new Date(), //结束日期
				input: '', //搜索
				loading: true,
				tableData: [],
				index: 1,
				total: 1,
			}
		},
		created() {
			this.getpoptotal(this.index)
		},
		methods: {
			excel(){
				this.$axios.post(api.getpoptotal, {
					"SDate": this.starTime,
					"EDate": this.endTime,
					"PagePara": {
						"Para": "",
						"PageSize": 10,
						"PageIndex": this.index - 1,
						"OrderbyString": "RegTotal",
						 "ToExcel": true
					}
				}).then(res => {
					if(res.data.isOK){
						if(res.data.data.ExcelResult && res.data.data.ExcelResult.isOK) {
							this.loading = false
							var urls = res.data.data.ExcelResult.data.filePath
							window.location.href = api.host+'/template/'+urls
						} else{
							this.loading = false
							this.$message.error(res.data.data.ExcelResult.msg);
						}
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			handleCurrentChange(val) {
				this.index = val
				this.getpoptotal(this.index)
			},
			look() {
				this.index = 1
				this.getpoptotal(this.index)
			},
			getpoptotal(val) {
				this.$axios.post(api.getpoptotal, {
					"SDate": this.starTime,
					"EDate": this.endTime,
					"PagePara": {
						"Para": "",
						"PageSize": 10,
						"PageIndex": val - 1,
						"OrderbyString": "RegTotal",
						 "ToExcel": false
					}
				}).then(res => {
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items ? res.data.data.Items : 1
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>